interface VisitorInfo {
  total: number;
  rows: {
    _id: string;
    ip: string;
    adInfoOb: {
      nation: string;
      district: string;
      city: string;
      province: string;
      lastTime: string;
    };
  }[];
}

interface VisitorInfoResponse {
  code: number;
  msg: string;
  data: VisitorInfo;
}
export default defineEventHandler(async (event) => {
  try {
    const query = getQuery(event);
    const page = parseInt(query.page as string) || 1;
    const pageSize = parseInt(query.pageSize as string) || 10;
    const response = await $fetch<VisitorInfoResponse>(
      `http://localhost:4003/api/visitorInfo?page=${page}&limit=${pageSize}`,
      {
        method: "GET",
      }
    );
    if (response.code === 0) {
      return {
        code: 200,
        message: "获取成功",
        data: {
          list: response.data.rows,
          total: response.data.total,
          page,
          pageSize,
        },
      };
    } else {
      return response;
    }
  } catch (error) {
    console.error("获取访客记录失败:", error);
    return {
      code: 500,
      message: "获取访客记录失败",
      data: {
        list: [],
        total: 0,
        page: 1,
        pageSize: 20,
        hasMore: false,
      },
    };
  }
});
